/**
 * @(#) CongMoneyMediator.as
 *
 * @date		2009. 03. 25.
 * @version		1.0
 * @author		baek, kwang hyoun
 * @description	건강보험증 신청 - Mediator
 * 				건강보험증을 조회하고 신청하는 Presentation Logic을 관리
 */
package com.skt.common_hr.empcont.view
{
	import com.skt.common_hr.common.puremvc.OverViewMediator;
	import com.skt.common_hr.empcont.EmpcontFacade;
	import com.skt.common_hr.empcont.view.components.EmpcontOverViewSac;
	import com.skt.common_hr.empcont.view.components.ReqFileUpload;
	
	import flash.events.Event;
	
	import mx.managers.PopUpManager;
	
	import org.puremvc.as3.multicore.interfaces.INotification;

	public class EmpcontMediator extends OverViewMediator
	{
		public static const NAME:String = "MedicineMediator";
		private var _bWaitingSave:Boolean = false;
		/**
		* 생성자
		*
		* @param
		* @return void
		*/
        public function EmpcontMediator( viewComponent:Object )
        {
            super( NAME, viewComponent );
        }

		/**
		* View를 초기화 한다.
		*	- View에 기본사항을 출력하고 data를 load
		* @param
		* @return void
		* 최초 한번만 불림
		*/
 		override protected function initializeView():void
 		{
			super.initializeView();
			view.addEventListener(EmpcontOverViewSac.NoticeWrite, onFileWrite);
			view.addEventListener(EmpcontOverViewSac.MODIFY_ITEM, onFileModify);
//			ReqFileUpload(view.oPopupFileUpload).addEventListener(EmpcontOverViewSac.NoticeOnlyFileDelete, onNoticeOnlyFileDelete);
//			ReqFileUpload(view.oPopupFileUpload).addEventListener(EmpcontOverViewSac.NoticeDelete, onNoticeDelete);
//			ReqFileUpload(view.oPopupFileUpload).addEventListener(EmpcontOverViewSac.GetFile, onBrowseFile);
 		}
		/***
		 * 활성화가 될때마다 불림.
		 */
		override protected function activatedView():void
		{
			super.activatedView();
			loadList();
		}
		
		public function loadList():void
 		{
 			view.initView();
 		}

		private var _reqFileUpload:ReqFileUpload = null;
		private function onFileWrite(event:Event=null):void
 		{
			var fUploadMediator:fileUploadMediator = facade.retrieveMediator(fileUploadMediator.NAME) as fileUploadMediator;
			if(fUploadMediator==null) {
	 			_reqFileUpload = PopUpManager.createPopUp(view.root, ReqFileUpload, true) as ReqFileUpload;
	 			PopUpManager.centerPopUp(_reqFileUpload);
				
				fUploadMediator = new fileUploadMediator(_reqFileUpload);
				facade.registerMediator(fUploadMediator);	
			}
			else {
				PopUpManager.addPopUp(_reqFileUpload, view.root, true);
			}
			_reqFileUpload.setFocus();
			ReqFileUpload(_reqFileUpload).cbDocDv.dataProvider = view._mainListFileDocCode;
			ReqFileUpload(_reqFileUpload).y = 200;	
			ReqFileUpload(_reqFileUpload).attachMode = 'WRITE';
			fUploadMediator.sendNotification(EmpcontFacade.MODE_WRITE_NOTICE,this);			
 		}
 		
 		private function onFileModify(event:Event):void
 		{			
			var fUploadMediator:fileUploadMediator = facade.retrieveMediator(fileUploadMediator.NAME) as fileUploadMediator;
			if(fUploadMediator==null) {
	 			_reqFileUpload = PopUpManager.createPopUp(view.root, ReqFileUpload, true) as ReqFileUpload;
	 			PopUpManager.centerPopUp(_reqFileUpload);
				
				fUploadMediator = new fileUploadMediator(_reqFileUpload);
				facade.registerMediator(fUploadMediator);	
			}
			else {
				PopUpManager.addPopUp(_reqFileUpload, view.root, true);
			}
			_reqFileUpload.setFocus();
			ReqFileUpload(_reqFileUpload).cbDocDv.dataProvider = view._mainListFileDocCode;
			ReqFileUpload(_reqFileUpload).y = 200;			
			ReqFileUpload(_reqFileUpload).attachMode = view._attachMode;
			ReqFileUpload(_reqFileUpload).oParent = view;
  			facade.sendNotification(EmpcontFacade.MODE_MODIFY_NOTICE, view._selectedFileVo);			
 		}
 		
		override protected function closedView():void
		{
			removeEventListener();
		}
		
		private function removeEventListener():void
 		{
			//view.removeEventListener(HthIcFacade.HthIcWrite, onClickNew);
 		}

		/**
		* 본 Class에서 처리해야할 Noti들을 등록한다.
		*
		* @param
		* @return void
		*/
		override public function listNotificationInterests():Array
		{
			return [
					EmpcontFacade.LOADLIST
					];
		}


		/**
		* Noti별로 처리한다.
		*
		* @param
		* @return void
		*/
		override public function handleNotification(note:INotification):void
		{
			super.handleNotification(note);
			switch(note.getName())
			{
				case EmpcontFacade.LOADLIST:
					loadList();
					break;
									
				default:
					break;
			}
		}

		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event handler (from View, Internal or....)
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
       private function get view():EmpcontOverViewSac
        {
            return viewComponent as EmpcontOverViewSac;
        }


	}
}